*RCRA Nationwide Hedonic Study
*Descriptive Stats for RCRA TSD site and Corrective Action data
*Created on: 1/13/2020
*Created by: Dennis Guignet
*Last revised: 5/22/2023
*Last revised by: Dennis Guignet

********************************************************************************

*This do-file performs descriptive stats on the processed dataset of TSDFs 
*	and Corrective Actions of interest. Generates statistics used in Appendix B.1
*	of final paper, and in Table 1 of main manuscript. 


********************************************************************************
********************************************************************************

*Bring in cleaned dataset of TSDFs and Corrective Actions.
use "$RCRAfolder\TSD_and_Corrective_Actions_FINAL.dta", clear

*Focus on contiguous US
count
tab Location_State
drop if Location_State=="AK"|Location_State=="GU"|Location_State=="HI" ///
	|Location_State=="PR"|Location_State=="VI"
count
tab TSD

*First perform descriptive stats on entire US. 
tab CA_Site
tab CA_complete if CA_Site==1

*start of corrective actions
tab CA_Start_YMD_miss
	*Note: Among RCRA sites of interest in study area, have 689 CAs, but 138 
	*	of those CAs do not have necessary start date fields included. 
tab CA_Start_yr if CA_Start_YMD_miss==0 	
	
*end of corrective action	
tab CA_End_YMD_miss 
tab CA_End_yr if CA_End_YMD_miss==0 


*RCRA site characteristics (Table A3 in Appendix B.1)
sum LQG SQG TSD recycler under_inj offsite_waste universal_TDR used_oil Ebroker HazWaste_Cnt 
local vars LQG SQG TSD recycler under_inj offsite_waste universal_TDR used_oil Ebroker
foreach v of local vars {
	tab `v' 
	}
tab LQG SQG 
tab TSD recycler 
sum HazWaste_Cnt, detail 
tab HazWaste_Cnt
*NAICS industry categories (Table A2 in Appendix B.1)
tab NAICS_miss
sum NAICS_ag NAICS_mining NAICS_utility NAICS_constrn NAICS_manuf ///
	NAICS_trade_transp NAICS_services NAICS_wastemgmt if NAICS_miss==0 
local vars NAICS_ag NAICS_mining NAICS_utility NAICS_constrn NAICS_manuf ///
	NAICS_trade_transp NAICS_services NAICS_wastemgmt
foreach v of local vars {
	tab `v' if NAICS_miss==0
 	}
	

*Corrective Action duration
gen CA_duration_days=CA_End_date_stata-CA_Start_date_stata if CA_Start_YMD_miss==0 ///
	& CA_End_YMD_miss==0 
replace CA_duration_days=. if CA_duration_days<0
	*Note: Three sites had negative duration, so set as missing.  
gen CA_duration_years=CA_duration_days/365.25
sum CA_duration_days CA_duration_years	
sum CA_duration_years, detail


*Descriptive stats table Corrective Action (CA) characteristics (Table 1 in main text)
tab CA_Site 
tab CA_Site CA_complete
sum  CA_basesite risk risk_miss RemedyConst PhysCtrls InstCtrls CA_complete ///
	CA_duration_years if CA_Site==1 
sum risk if risk_miss==0 & CA_Site==1 
tab risk_miss if CA_Site==1
count if RemedyConst+PhysCtrls+InstCtrls>0 & CA_Site==1 
count if RemedyConst+PhysCtrls+InstCtrls==1 & CA_Site==1 
count if RemedyConst+PhysCtrls+InstCtrls==2 & CA_Site==1 
count if RemedyConst+PhysCtrls+InstCtrls==3 & CA_Site==1 
count if RemedyConst+PhysCtrls+InstCtrls>3 & CA_Site==1 


*Check how many post and mid- CA sites at end of study period 
	*Note: Used to provide details for later welfare excercise.
gen completed=0
replace completed=1 if CA_End_date_stata<=date("12/31/2018", "MDY") ///
	& CA_End_date_stata!=.
	*Note: 195 completed CA sites by end of study period. 
gen open=0
replace open=1 if (CA_Start_date_stata<=date("12/31/2018", "MDY") /*& (CA_Start_date_stata!=.)*/) ///
		& ((CA_End_date_stata!=. & CA_End_date_stata>date("12/31/2018", "MDY")) | CA_End_date_stata==.) 
	*Note: 406 open CA sites by end of study period. Don't need missing start date
	*	condition b/c end of study period, and it's inclusion actually doesn't 
	*	change the count. 
tab CA_Site
tab CA_Site open
tab CA_Site completed

*replace sums in table with these for complete site, because earlier one
*	included completions after end of study period in 2018 (added 12/11/2022). 
sum completed if CA_Site==1 
sum CA_duration_years if completed==1

tab open completed
tab open completed if CA_Site==1

*END